package com.zym.controller;

import com.zym.entity.Category;
import com.zym.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "分类")
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @ApiOperation("查询所有")
    @GetMapping("/list")
    public Map<String,Object> list(){
        System.out.println("查询所有");
        List<Category> categoryList=categoryService.buildTree();
        Map<String,Object> map=new HashMap<>();
          map.put("data",categoryList);
        return map;
    }
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public Map<String,Object> getById(@PathVariable("id") Long id){
        Category byId = categoryService.getById(id);
        Map<String,Object> map=new HashMap<>();
        map.put("data",byId);
        return map;
    }
}
